/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.stat;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;

public class q {
    private static String a = "QHttp";

    public static String a(Context paramContext, String paramString1, String paramString2) {
        HttpResponse localHttpResponse = null;
        HttpPost localHttpPost = null;
        ByteArrayEntity localByteArrayEntity = null;
        String str = "";
        int i = 0;
        try {
            localHttpPost = new HttpPost(paramString1);
            localByteArrayEntity = new ByteArrayEntity(s.a(paramString2.getBytes()));
            localHttpPost.setEntity(localByteArrayEntity);
            HttpClient localHttpClient = a(paramContext);
            localHttpResponse = localHttpClient.execute(localHttpPost);
            if (localHttpResponse.getStatusLine() != null) {
                i = localHttpResponse.getStatusLine().getStatusCode();
                str = EntityUtils.toString(localHttpResponse.getEntity());
            }
        } catch (Exception localException) {
            x.a(a, localException);
        } catch (Error localError) {
            x.a(a, localError);
        }
        return str;
    }

    private static HttpClient a(Context paramContext) {
        BasicHttpParams localBasicHttpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(localBasicHttpParams, 60000);
        HttpConnectionParams.setSoTimeout(localBasicHttpParams, 60000);
        HttpConnectionParams.setSocketBufferSize(localBasicHttpParams, 204800);
        HttpClientParams.setRedirecting(localBasicHttpParams, true);
        HttpHost localHttpHost = a(b(paramContext));
        if (localHttpHost != null)
            localBasicHttpParams.setParameter("http.route.default-proxy", localHttpHost);
        return new DefaultHttpClient(localBasicHttpParams);
    }

    private static String b(Context paramContext) {
        String str = "";
        try {
            ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                    .getSystemService("connectivity");
            NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
            if ((localNetworkInfo != null) && (localNetworkInfo.isAvailable()))
                str = localNetworkInfo.getExtraInfo();
        } catch (Exception localException) {
            x.a(a, "ex: " + localException.toString());
        }
        return str;
    }

    private static HttpHost a(String paramString) {
        if (!(TextUtils.isEmpty(paramString))) {
            paramString = paramString.toLowerCase();
            if ((paramString.startsWith("uniwap")) || (paramString.startsWith("3gwap")))
                return new HttpHost("10.0.0.172", 80);
            if (paramString.startsWith("cmwap"))
                return new HttpHost("10.0.0.172", 80);
            if (paramString.startsWith("ctwap"))
                return new HttpHost("10.0.0.200", 80);
        }
        return null;
    }
}